package nc;
import java.util.*;
import org.junit.*;

public class Yuanfudao {
    
    static class Main {

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[][] nums = new int[n][2];

            for (int i = 0; i < n; i++) {
                nums[i][0] = sc.nextInt();
                nums[i][1] = sc.nextInt();
            }

            sc.close();    

            Arrays.sort(nums, (a, b) -> a[0] != b[0] ? a[0] - b[0] : a[1] - b[1]);  
            Queue<int[]> queue = new PriorityQueue<>((a, b) -> a[1] - b[1]);
            queue.offer(nums[0]);

            for (int i = 1; i < n; i++) {
                int[] last = queue.peek();
                if (last[1] <= nums[i][0]) {
                    queue.poll();
                    queue.offer(new int[]{last[0], nums[i][1]});
                } else {
                    queue.offer(nums[i]);
                }
            }

            System.out.println(queue.size());
        }
    }

}

/**
4
1 4
1 2
1 3
3 4
 * 
 */